/*
 * 学生详情->平台业务数据->掌大生活
 * @Author: ice
 * @Date: 2018-09-27 19:33:31
 * @Last Modified by: ice
 * @Last Modified time: 2018-10-08 18:22:11
 */
<template>
    <div class="plt-market-wrap">
        <template v-if="orderData">
            <el-card class="box-card">
                <div
                    slot="header"
                    class="clearfix card-header">
                    任务系统
                </div>
                <div class="card-content">
                    <div class="user-info">
                        <div
                            class="user-header"
                            :style="'background-image: url('+head_img+')'"/>
                        <div class="user-name">
                            <div class="user-name-top">{{ true_name }}</div>
                        </div>
                    </div>
                    <div class="user-detail-unit">
                        <div class="user-detail-title">领取任务数量</div>
                        <div class="user-detail-value">{{ total }}</div>
                    </div>
                    <div class="user-detail-spliter" />
                    <div class="user-detail-unit">
                        <div class="user-detail-title">完成任务数量</div>
                        <div class="user-detail-value">{{ complete }}</div>
                    </div>
                    <div class="user-detail-spliter" />
                    <div class="user-detail-unit">
                        <div class="user-detail-title">任务获取积分</div>
                        <div class="user-detail-value">{{ score }}</div>
                    </div>
                </div>
                <div class="total-task">
                    <div class="total-task-title">他的全部任务</div>
                    <div class="total-task-value">{{ tasks }}</div>
                </div>
            </el-card>
            <el-card class="box-card no-padding">
                <div
                    slot="header"
                    class="clearfix card-header">
                    <span class="card-header-label">订单总数：</span>
                    <span class="card-header-value">{{ page.total_count }}</span>
                    <span class="card-header-label">订单总额（元）：</span>
                    <span class="card-header-value">{{ totalMoney }}</span>
                </div>
                <div class="card-content">
                    <el-table
                        :data="orderData"
                        style="width: 100%">
                        <el-table-column
                            prop="order_no"
                            label="订单ID"
                            width="180" />
                        <el-table-column
                            prop="order_type"
                            label="购买类型"
                            :formatter="orderTypeFormatter"
                            width="100" />
                        <el-table-column
                            prop="create_time"
                            width="180"
                            label="下单时间">
                            <template slot-scope="scope">
                                <div>{{ scope.row.create_time*1000 | dateFormatter('yyyy-MM-dd HH:mm-ss') }}</div>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="good_title"
                            label="商品名称">
                            <template slot-scope="scope">
                                <el-popover
                                    trigger="hover"
                                    placement="top">
                                    <p>{{ scope.row.good_title }}</p>
                                    <div
                                        slot="reference"
                                        class="ellipsis good-title">
                                        {{ scope.row.good_title }}
                                    </div>
                                </el-popover>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="order_num"
                            label="数量" />
                        <el-table-column
                            prop="cate_title"
                            label="商品分类" />
                        <el-table-column
                            prop="good_spec"
                            label="规格" />
                        <el-table-column
                            prop="order_price"
                            label="价格(￥)" />
                        <!-- 订单状态，0:待支付 1:拼团中(已支付) 2:拼团成功(待发货) 3:待收货 4:已完成 -1:订单取消 -2:拼团失败 -->
                        <el-table-column
                            prop="order_status"
                            label="订单状态">
                            <template slot-scope="scope">
                                <div class="good-status">
                                    <div
                                        class="status-point"
                                        :class="{'status-going': scope.row.order_status >=0 &&scope.row.order_status <=3, 'status-success': scope.row.order_status == 4, 'status-disabled': scope.row.order_status <0}"/>
                                    <div class="status-text">{{ scope.row.order_status | filterStatus }}</div>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="order_money"
                            label="付款金额(￥)" />
                    </el-table>
                </div>
                <el-pagination
                    v-if="page.total_page > 1"
                    class="page-bar"
                    :current-page="page.now_page"
                    background
                    layout="prev, pager, next"
                    :page-size="page.now_page_size"
                    :total="page.total_count"
                    @current-change="fnGetOrders" />
            </el-card>
        </template>
        <div
            class="empty"
            v-else>
            <div class="empty-img"/>
            <div class="empty-msg">暂无数据</div>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    data() {
        return {
            true_name: '',
            head_img: '',
            loading: false,

            orderData: '',
            page: {
                now_page: 1,
                total_page: 0,
                page_size: 0,
                total_count: 0,
                now_page_size: 0,
            },
            queryTime: 0,

            score: 0,
            complete: 0,
            total: 0,
            tasks: '',
        };
    },
    filters: {
        filterStatus(val){
            //  订单状态，0:待支付 1:拼团中(已支付) 2:拼团成功(待发货) 3:待收货 4:已完成 -1:订单取消 -2:拼团失败
            switch(val){
                case 0: return '待支付';
                case 1: return '拼团中(已支付)';
                case 2: return '拼团成功(待发货)';
                case 3: return '待收货';
                case 4: return '已完成';
                case -1: return '订单取消';
                case -2: return '拼团失败';
                default: return '未知';
            }
        }
    },
    methods: {
        orderTypeFormatter(row, col, val){
            switch(val){
                case 1: return '单独购买';
                case 2: return '团长开团';
                case 3: return '参团购买';
                default: return '--';
            }
        },
        init() {
            this.hd_user_no = this.$route.query.hd_user_no ? this.$route.query.hd_user_no : '';
            if (this.hd_user_no && this.orderData.length <= 0) {
                this.fnGetTasks();
                this.fnGetOrders(1);
                this.fnGetStudent();
            }
        },
        fnGetStudent() {
            this.$post('/studata/student%5Cmarket%5Cbuyer_user', {
                hd_user_no: this.hd_user_no
            }, resp => {
                if (resp.code == 1) {
                    this.true_name = resp.data.nickname;
                    this.head_img = resp.data.head_img;
                } else {
                    // this.$message({
                    //     type: 'warning',
                    //     message: resp.msg,
                    //     center: true
                    // });
                }
            });
        },
        fnGetTasks() {
            this.$post('/studata/platform%5Cmarket%5Ctask_buyer_task', {
                hd_user_no: this.hd_user_no
            }, resp => {
                if (resp.code == 1) {
                    this.score = resp.data.score;
                    this.complete = resp.data.complete;
                    this.total = resp.data.total;
                    this.tasks = resp.data.list.reduce((res, currentValue, currentIndex, arr) => {
                        return res + (currentValue.title + '；');
                    }, '');
                } else {
                    // this.$message({
                    //     type: 'warning',
                    //     message: resp.msg,
                    //     center: true
                    // });
                }
            });
        },
        fnGetOrders(page) {
            if(page){
                this.page.now_page = page;
            }
            let currTime = new Date().getTime();

            this.queryTime = currTime;

            this.loading = true;
            this.$post('/studata/platform%5Cmarket%5Corder_list', {
                page_id: this.page.now_page,
                hd_user_no: this.hd_user_no
            }, resp => {
                if (this.queryTime != currTime) {
                    return;
                }
                this.loading = false;
                if (resp.code == 1) {
                    this.page = resp.data.page;
                    this.totalMoney = resp.data.pay_money;
                    this.orderData = resp.data.list;
                } else {
                    // this.$message({
                    //     type: 'warning',
                    //     message: resp.msg,
                    //     center: true
                    // });
                }
            });
        },
    }
};

</script>

<style lang="less" scoped>
    .box-card{
        margin-bottom: 20px;
    }
    .page-bar {
      text-align: right;
      margin: 20px 0;
    }
    .plt-market-wrap {
      padding: 20px;
      padding-top: 0;
      box-sizing: border-box;
    }
    .card-content {
      display: flex;
      align-items: center;
      justify-content: flex-start;
    }
    .user-info {
      flex-shrink: 0;
      width: 400px;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 20px 0;
      .user-header {
        width: 72px;
        height: 72px;
        margin-right: 24px;
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
      }
      .user-name {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        &-top {
          font-size: 20px;
          font-weight: bold;
          color: rgba(0, 0, 0, 0.85);
          line-height: 28px;
        }
      }
    }
    .user-detail {
      &-unit {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0 25px;
      }
      &-title {
        font-size: 14px;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.45);
        line-height: 22px;
      }
      &-value {
        font-size: 30px;
        color: rgba(0, 0, 0, 0.85);
        line-height: 38px;
      }
      &-spliter {
        width: 1px;
        height: 40px;
        background: #e9e9e9;
      }
    }

    .total-task {
      margin-top: 10px;
      padding: 15px;
      background: rgba(250, 250, 250, 1);
      border-radius: 4px;
      &-title {
        font-size: 14px;
        font-weight: bold;
        color: rgba(0, 0, 0, 1);
        line-height: 20px;
        margin-bottom: 10px;
      }
      &-value {
        font-size: 14px;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.65);
        line-height: 20px;
      }
    }
    .card-header {
      font-size: 16px;
      font-weight: bold;
      color: rgba(0, 0, 0, 0.85);
      line-height: 24px;
      &-label {
        font-size: 16px;
        font-weight: bold;
        color: rgba(0, 0, 0, 0.85);
        line-height: 24px;
      }
      &-value {
        font-size: 16px;
        font-weight: bold;
        color: #f5a623;
        line-height: 24px;
        margin-right: 50px;
      }
    }

    .good-title {
      width: 168px;
    }
    .good-status {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .status-point {
        display: inline-block;
        width: 6px;
        height: 6px;
        border-radius: 6px;
        margin-right: 8px;
      }
      .status-text {
        flex: 1;
        font-size: 14px;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.65);
        line-height: 22px;
      }
    }
</style>